package com.example.smartfridge;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.example.smartfridge.R;
import com.id2216.fridge.data.ShoppingItem;

public class ShoppingAdapter extends ArrayAdapter<ShoppingItem> {

	    Context context;
	    int layoutResourceId;   
	    List<ShoppingItem> data = null;
	    
		public ShoppingAdapter(Context context, int resource, List<ShoppingItem> shoppingItemList) 
		{
			super(context, resource, shoppingItemList);
			
	        this.layoutResourceId = resource;
	        this.context = context;
	        this.data = shoppingItemList;
	 	}
		
		
		@Override
	    public View getView(int position, View convertView, ViewGroup parent) {
	        View row = convertView;
	        ShoppingHolder holder = null;
	       
	        if(row == null)
	        {
	            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
	            row = inflater.inflate(layoutResourceId, parent, false);
	           
	            holder = new ShoppingHolder();
	            holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
	            holder.txtQuantity = (TextView)row.findViewById(R.id.txtQuantity);
	            holder.checkShoppingDone = (CheckBox)row.findViewById(R.id.shoppingDoneCheckBox);
	           
	            row.setTag(holder);
	        }
	        else
	        {
	            holder = (ShoppingHolder)row.getTag();
	        }
	       
	        ShoppingItem item = data.get(position);
	        holder.txtTitle.setText(item.getName());
	        holder.txtQuantity.setText(item.getQuantityString());
	        //holder.txtExpire.setText(item.getExpireDay());
	        
	        // Set text style and color
//	        if(item.isExpire() == true)
//	        {	
//	        	holder.txtTitle.setTextColor(Color.parseColor("#800000"));
//	        	holder.txtTitle.setTypeface(null,Typeface.BOLD);
//	        	holder.txtExpire.setTextColor(Color.parseColor("#800000"));
//	        	holder.txtExpire.setTypeface(null,Typeface.BOLD);
//	        }
//	        else
//	        {
//	            holder.txtTitle.setTextColor(Color.BLACK);
//	        	holder.txtTitle.setTypeface(null,Typeface.NORMAL);
//	            holder.txtExpire.setTextColor(Color.BLACK);
//	        	holder.txtExpire.setTypeface(null,Typeface.NORMAL);
//	        }
	        return row;
	    }
		
		static class ShoppingHolder
		{
			CheckBox checkShoppingDone;
			TextView txtTitle;
			TextView txtQuantity;
		}

}
